import 'package:enterprise_v6_app/app/components/custom_app_bar.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/widget_extension.dart';
import 'package:enterprise_v6_app/app/core/utils/interface.dart';
import 'package:enterprise_v6_app/app/modules/application/basic_information/file_management/file_list/certificate_file_details/certificate_file_details_controller.dart';

/// 证书文件-文件详情
class CertificateFileDetailsPage extends StatelessWidget {
  CertificateFileDetailsPage({super.key});

  final controller = Get.put(CertificateFileDetailsController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
        init: controller,
        builder: (_) {
          return Scaffold(
            appBar: CustomAppBar(
              titleText: '文件详情',
            ),
            body: Container(
              alignment: Alignment.topCenter,
              color: const Color(0xffF5F5F6),
              child: SingleChildScrollView(
                child: Column(
                  children: [
                    Container(
                      height: 38.w,
                      alignment: Alignment.centerLeft,
                      padding: EdgeInsets.only(left: 16.w),
                      child: Text('基本信息', style: TextStyle(fontSize: 12.sp, color: const Color(0xFF7C7D93))),
                    ),
                    Container(
                      height: 2.w,
                      color: const Color(0xFF587DF5),
                    ),
                    Container(
                      color: Colors.white,
                      alignment: Alignment.topLeft,
                      padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 15.w),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Text(controller.fileEntity.certificateName!,
                              style: TextStyle(
                                fontSize: 16.sp,
                                fontWeight: FontWeight.w500,
                                color: const Color(0xFF262F38),
                              )),
                          AppGaps.vGap12,
                          _getTextView(title: '状态：', value: controller.fileEntity.statusName!),
                          AppGaps.vGap12,
                          _getTextView(title: '类型：', value: _getTypeText(controller.fileEntity.fileChildType!)),
                          AppGaps.vGap12,
                          _getTextView(title: '持证对象：', value: controller.fileEntity.fileObjectName!),
                          AppGaps.vGap12,
                          // 类型为人员时才会显示
                          Visibility(
                              visible: controller.fileEntity.fileChildType! == 2,
                              child: Column(
                                children: [
                                  _getTextView(title: '是否特种作业：', value: controller.fileEntity.specialType! == 1 ? '是' : '否'),
                                  AppGaps.vGap12,
                                  _getTextView(title: '特种作业：', value: controller.fileEntity.specialWorks!),
                                  AppGaps.vGap12,
                                ],
                              )),
                          _getTextView(title: '颁发日期：', value: controller.fileEntity.obtainDate!),
                          AppGaps.vGap12,
                          _getTextView(title: '到期日期：', value: controller.fileEntity.becomeDueDate!),
                          AppGaps.vGap12,
                          Text('证书：',
                              style: TextStyle(
                                fontSize: 13.sp,
                                height: 1.2,
                                fontWeight: FontWeight.w400,
                                color: const Color(0xffA5A6B5),
                              )),
                          AppGaps.vGap8,
                          Wrap(
                              spacing: 20.w,
                              children: controller.picList.map<Widget>((item) {
                                return Container(
                                  width: 80.w,
                                  height: 67.w,
                                  margin: EdgeInsets.only(bottom: 10.w),
                                  decoration: BoxDecoration(
                                    color: const Color(0xffF7F7FB),
                                    border: Border.all(color: const Color(0xffEBEDF0), width: 1.w),
                                    borderRadius: BorderRadius.circular(8.w),
                                    image: DecorationImage(
                                      image: NetworkImage(Interface.fileUrl + item),
                                      fit: BoxFit.cover,
                                    ),
                                  ),
                                ).clickShowLarge(url: Interface.fileUrl + item);
                              }).toList()),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            ),
          );
        });
  }

  /// 获取类型显示字段
  String _getTypeText(int fileChildType) {
    switch (fileChildType) {
      case 1:
        return '企业';
      case 2:
        return '人员';
      case 3:
        return '设备';
      default:
        return '';
    }
  }

  /// 获取字段显示
  Widget _getTextView({required String title, required String value, Color? valueColor}) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        SizedBox(
          width: 100.w,
          child: Text(
            title,
            style: TextStyle(
              fontSize: 13.sp,
              height: 1.2,
              fontWeight: FontWeight.w400,
              color: const Color(0xffA0A7B5),
            ),
          ),
        ),
        Expanded(
            child: Text(
          value,
          style: TextStyle(
            fontSize: 14.sp,
            height: 1.2,
            fontWeight: FontWeight.w400,
            color: valueColor ?? const Color(0xff495061),
          ),
        ))
      ],
    );
  }
}
